<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<form class="layui-form" action="" id="type" onsubmit="return false" style="padding-top: 10px;width: 450px">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入名称" lay-verify="title"  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">适合年级</label>
        <div class="layui-input-block">
            {foreach $grade as $value}
                <input type="checkbox" name="grade_id[]" title="{$value.grade_title}" value="{$value.id}">
            {/foreach}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单位</label>
        <div class="layui-input-block">
            <input type="text" name="unit" placeholder="请输入单位" lay-verify="unit"  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">立即添加</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>
</body>
<script>
    layui.use(['form'],function () {
        var form = layui.form;
        form.verify({
            title: function(value){
                if(!value){
                    return '请输入名称';
                }
            },
            unit:function (value) {
                if(!value){
                    return '请输入单位';
                }
            }
        });
        form.on('submit(*)', function(data) {
            $.ajax({
                type:'POST',
                url:'/constitution_type/type_insert',
                data:$("#type").serialize(),
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            parent.window.location.reload();
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        });
    })
</script>
</html>